<?php
	class ResourceDao extends BaseDao {
		
		function addResource($resource) {
			parent::getConnect();
			$type = $resource->getType();
			$data = $resource->getData();
			$fileName = $resource->getFileName();
			$fileSize = $resource->getFileSize();
			$fileType = $resource->getFileType();
			$rs = mysql_query("insert into resource (type, data, file_name, file_size, file_type, update_date) values ('$type', '$data', '$fileName', '$fileSize', '$fileType', now())");
			$id = mysql_insert_id();
			$resource->setId($id);
			parent::releaseConnect();
		}
		
		function deleteResource($id) {
			parent::getConnect();
			mysql_query("delete from resource where id=$id");
			parent::releaseConnect();
		}
		
		function getResource($id) {
			parent::getConnect();
			$rs = mysql_query("select id, type, data, file_name, file_size, file_type, update_date from resource where id='$id'");
			$record = mysql_fetch_object($rs);
			$resource = new Resource();
			$resource->setData($record->data);
			$resource->setFileName($record->file_name);
			$resource->setFileSize($record->file_size);
			$resource->setFileType($record->file_type);
			$resource->setId($record->id);
			$resource->setType($record->type);
			$resource->setUpdateDate($record->update_date);
			parent::releaseConnect();
			return $resource;
		}
		
	}
?>